﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;

namespace ThreadSafe.JSense.VS2012
{
   class JSense
   {
      private DTE _applicationObject;

      public JSense(DTE dte)
      {
         _applicationObject = dte;
      }

      public void Initialize()
      {
         var properties = _applicationObject.get_Properties("TextEditor", "JavaScript Specific");
         var implicitValueGroups = ((string)properties.Item("ImplicitReferencesString").Value).Split(';');

         var implicitValues = implicitValueGroups[1].Split('|');

         if (implicitValues.Any(i => i.EndsWith("@JSense.js"))) return;

         implicitValueGroups[1] += "|~/@JSense.js";
         var joinValue = String.Join(";", implicitValueGroups);

         properties.Item("ImplicitReferencesString").Value = joinValue;
      }
   }
}
